﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Kalman;
using Kalman.Extensions;
using Kalman.Jwt;
using Kalman.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
//using Renci.SshNet.Security;

namespace QuDao.Api.Controllers
{
    /// <summary>
    /// 用户API
    /// </summary>
    public class UserController : ApiControllerBase
    {
        /// <summary>
        /// 获取用户详情数据
        /// </summary>
        /// <param name="userID"></param>
        /// <returns></returns>
        [HttpGet]
        public UserDetailsDto GetDetails(long userID)
        {
            var dto = UserBO.Instance.GetDetails(userID);
            return dto;
        }

        /// <summary>
        /// 获取推荐的会员用户列表（团队成员列表）
        /// </summary>
        /// <param name="tid">租户ID</param>
        /// <param name="recoID">推荐人ID</param>
        /// <param name="userType">用户类型：A,B,C，为空表示获取全部</param>
        /// <returns></returns>
        [HttpGet]
        public List<UserDto> GetRecoList([FromHeader] int tid, long recoID, string userType = "")
        {
            return UserBO.Instance.GetRecoList(tid, recoID, userType);
        }

        /// <summary>
        /// 更新指定字段值（支持字段：TrueName-姓名，Mobile-手机号，AvatarUrl-头像，ReceiverName-收货人姓名，ReceiverPhone-收货人电话，ReceiveAddress-收货人地址
        /// ，ClearingBank-结算银行名称，BankAccountName-开户名，BankCardNo-银行卡号）
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <param name="fieldName">字段名</param>
        /// <param name="fieldValue">字段值</param>
        /// <returns></returns>
        [HttpPost]
        public bool Update(long id, string fieldName, string fieldValue)
        {
            UserBO.Instance.Update(id, fieldName, fieldValue);
            return true;
        }

        /// <summary>
        /// 更新用户所属区域信息（省市区/县）
        /// </summary>
        [HttpPost]
        public bool UpdateArea(long id, int provinceID, string provinceName, int cityID, string cityName, int countyID, string countyName)
        {
            UserBO.Instance.UpdateArea(id, provinceID, provinceName, cityID, cityName, countyID, countyName);
            return true;
        }


        /// <summary>
        /// 更新结算银行账户信息
        /// </summary>
        /// <param name="id">会员用户ID</param>
        /// <param name="bankName">结算银行名称</param>
        /// <param name="accountName">开户名称（姓名或单位）</param>
        /// <param name="bankCardNo">开户银行卡号</param>
        /// <returns></returns>
        [HttpPost]
        public bool UpdateBankInfo(long id, string bankName, string accountName, string bankCardNo)
        {
            UserBO.Instance.UpdateBankInfo(id, bankName, accountName, bankCardNo);
            return true;
        }


    }
}
